// pages/main/index/my_store/my_store.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    storeId:"",
    scrollTop: 0,
    jobType:1,
    latitude: 0,
    longitude: 0,
    tabs:["全职","兼职"],
    store_data:{},//门店详情
    store_lists: [],//门店列表
    hyNamesList: [],//行业标签数组
    workEnvUrls: [],//轮播图
    store_distance: '',
  },
  passMap:{
    lat: null,
    lng: null,
    jobType: 1,
    storeId: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const argMap = JSON.parse(options.param)
    //岗位id保存
    this.storeId = argMap.id
    //列表参数
    this.passMap.storeId = this.storeId
    this.passMap.lat = this.latitude
    this.passMap.lng = this.longitude
    this.passMap.jobType = this.jobType
    console.log(argMap)

    //获取门店详情数据
    this.getStoreInfo()
  },

  //tab切换
  selectTab(e){
    const tabIndex =e.detail.tabIndex;
    if(tabIndex == 0){
      this.data.jobType = 1;
      this.passMap.jobType = 1
    }else{
      this.data.jobType = 2;
      this.passMap.jobType = 2
    }
    //列表刷新
    const jobListView = this.selectComponent(".jobList")
    jobListView.getJobList(this.passMap, false);
  },

  //门店详情
  getStoreInfo() {
    const that = this;
    let commitData = {
      id: this.storeId
    }

    app.$http.getStoreInfo(commitData).then(res=>{
      // console.log(JSON.stringify(res))
      this.store_data = res
      this.hyNamesList = res.hyNames?res.hyNames.split(','):[]
      this.workEnvUrls = res.photos?res.photos.split(','):[]

      this.setData({
        store_data: this.store_data,
        hyNamesList: this.hyNamesList,
        workEnvUrls: this.workEnvUrls
      })

      // this.store_distance = getDistanceWeb(this.latitude, this.longitude, res.addressLat,res.addressLng)
    })
  },

  //开始滚动
  onPageScroll (e) { 
    console.log('滚起来')
    this.scrollTop= e.scrollTop
    this.setData({
      scrollTop: this.scrollTop
    })
  },

  //下拉刷新
  onPullDownRefresh(){
    const jobListView = this.selectComponent(".jobList")
    jobListView.getJobList(this.passMap, false);
  },

  //上拉加载
  onReachBottom(){
    const jobListView = this.selectComponent(".jobList")
    jobListView.getJobList(this.passMap, true);
  }
})